/**
 *@Description
 *@author your name
 *@createDate 2011-7-6 上午06:06:33
 *@version V1.0
 */
package com.welldone.service.vegetables;

import java.util.List;
import java.util.Map;
import java.util.UUID;

import com.welldone.service.DBService;

public class VegetablesManager {

	/**
	 * 添加蔬菜
	 *@author your name
	 *@createDate 2011-7-6
	 *@param map
	 *@return
	 */
	public boolean addVegetables(Map map){
		boolean flag = false;
		String sql="insert into t_vegetables (vegetablesId,unit,type,price,isSpecials,specialsPrice,vegetablesStatus) values(?,?,?,?,?,?,?)";
		String vegetablesId = UUID.randomUUID().toString();
		Object[] args = {vegetablesId,map.get("unit"),map.get("type"),map.get("price"),map.get("isSpecials"),map.get("vegetablesStatus")};
		int result = DBService.getJdbcTemplate().update(sql, args);
		if(result!=-1){
			flag = true;
		}
		return flag;
	}
	
	/**
	 * 更新蔬菜
	 *@author your name
	 *@createDate 2011-7-6
	 *@param map
	 *@return
	 */
	public boolean updateVegetables(Map map){
		boolean flag = false;
		String sql="update t_vegetables se unit=?,type=?,price=?,isSpecials=?,specialsPrice=?,vegetablesStatus=? where vegetablesId = ?";
		Object[] args = {map.get("unit"),map.get("type"),map.get("price"),map.get("isSpecials"),map.get("vegetablesStatus"),map.get("vegetablesId")};
		int result = DBService.getJdbcTemplate().update(sql, args);
		if(result!=-1){
			flag = true;
		}
		return flag;
	}
	
	/**
	 * 更新蔬菜
	 *@author your name
	 *@createDate 2011-7-6
	 *@param map
	 *@return
	 */
	public boolean deleteVegetables(String vegetablesId){
		boolean flag = false;
		String sql="delete from t_vegetables where vegetablesId = ?";
		Object[] args = {vegetablesId};
		int result = DBService.getJdbcTemplate().update(sql, args);
		if(result!=-1){
			flag = true;
		}
		return flag;
	}
	
	
	/**
	 * 得到所有菜
	 *@author your name
	 *@createDate 2011-7-6
	 *@return
	 */
	public List getAllVegetables(){
		String sql = "select * from t_vegetables";
		return DBService.getJdbcTemplate().queryForList(sql);
	}
	
	/**
	 * 根据类型得到所有菜
	 *@author your name
	 *@createDate 2011-7-6
	 *@param typeId
	 *@return
	 */
	public List getVegetablesByType(String typeId){
		String sql = "select * from t_vegetables where type = ?";
		Object[] args = {typeId};
		return DBService.getJdbcTemplate().queryForList(sql,args);
	}
	
	/**
	 * 查询特价菜
	 *@author your name
	 *@createDate 2011-7-6
	 *@return
	 */
	public List getVegetablesBySpecials(){
		String sql = "select * from t_vegetables where isSpecials = 1";
		return DBService.getJdbcTemplate().queryForList(sql);
	}
	
	/**
	 * 更新菜的状态
	 *@author your name
	 *@createDate 2011-7-6
	 *@param status
	 *@return
	 */
	public boolean updateVegetablesStauts(String status){
		boolean flag = false;
		String sql = "update t_vegetables set vegetablesStatus = ?";
		Object[] args = {status};
		int result = DBService.getJdbcTemplate().update(sql,args);
		if(result !=-1){
			flag = true;
		}
		return flag;
	}
	
	
	
}


